﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Collections;
using System.Runtime.InteropServices;
namespace TH10_Dat_Tools
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            System.Windows.Forms.ContainerControl.CheckForIllegalCrossThreadCalls = false;
        }
        /// <summary>
        /// 选择文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void On_SelectDatFile(object sender, EventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();
            op.CheckFileExists = false;
            op.Filter = "DAT文件|*.dat";
            DialogResult dr = op.ShowDialog();
            if (dr != DialogResult.OK)
                return;
            this.txt_DatFile.Text = op.FileName;
        }

        /// <summary>
        /// 选择工作目录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void On_SelectDir(object sender, EventArgs e)
        {
            LocalDirDlg DirDlg = new LocalDirDlg();
            if (DirDlg.DisplayDialog("选择输出文件夹") == DialogResult.OK)
                this.txt_Dir.Text = DirDlg.Path;
        }


        private void On_Unpack(object sender, EventArgs e)
        {
            //参数合法性判断
            if (File.Exists(this.txt_DatFile.Text) != true)
            {
                MessageBox.Show("源Dat文件不存在");
                return;
            }
            if (txt_Dir.Text == string.Empty)
            {
                MessageBox.Show("请选择工作文件夹");
                return;
            }
            if (Directory.Exists(this.txt_Dir.Text) != true)
            {
                Directory.CreateDirectory(txt_Dir.Text);
            }
            
            //解包文件
            UnPackFiles.UnPack(this.txt_DatFile.Text, txt_Dir.Text);

        }

        private void On_Pack(object sender, EventArgs e)
        {
            //参数合法性判断
            if (txt_Dir.Text == string.Empty)
            {
                MessageBox.Show("请选择工作文件夹");
                return;
            }
            if (txt_DatFile.Text == string.Empty)
            {
                MessageBox.Show("请选择目标Dat文件");
                return;
            }
            
            PackFiles.Pack(this.txt_DatFile.Text, txt_Dir.Text);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            
        }

    }
}
